#!/bin/bash

# 定义函数：使用sudo su命令运行脚本
run_with_sudo_su() {
  if [ "$(whoami)" != "root" ]; then
    sudo su -s "$0"
    exit
  fi
}
export -f run_with_sudo_su

# 定义函数：使用exec sudo命令运行脚本
run_with_exec_sudo() {
  if [ "$(whoami)" != "root" ]; then
    exec sudo "$0" "$@"
    exit
  fi
}
export -f run_with_exec_sudo

# 主函数，提供用户选择
main() {
  # run_with_sudo_su "$@"
  run_with_exec_sudo "$@"

  echo "Hello $(whoami)"
}

# 检查脚本是否被直接执行
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
  main "$@"
fi
